<!--本文件由FirstUI授权予关赛川（手机号： 1 5  60  05 1  520 5，身份证尾号：22 6  5 1 9）专用，请尊重知识产权，勿私下传播，违者追究法律责任。-->
<template>
	<view class="payCont">
		<view class="contA marin25">
			<view class="cont-paycont">
				<view class="cont-buy" v-if="form.zt ==1">
					购买成功
				</view>
				<view class="cont-buy" v-if="form.zt ==3">
					申请退款中
				</view>
				<view class="succes-text">
					<fui-button background="#fff" color="#35743D" borderColor="#35743D" radius='50rpx' width='218rpx'
						height='50rpx' size='28' @click='lookOrder'>查看订单</fui-button>
				</view>
			</view>
			<!-- 购买内容店名等信息 -->
			<view class="buy-name">
				<view class="b-title">
					{{form.mname}}
				</view>
				<view class="b-num">
					·{{form.number}}
				</view>
			</view>
			<!-- 二维码 -->
			<view class="buy-code" v-if="form.zt ==1">
				<view class="yuan1">

				</view>
				<view class="yuan2">

				</view>
				<view class="img-border  ">
					<tki-qrcode v-if="ifShow" cid="qrcode1" ref="qrcode" :val="val" :size="size" :unit="unit" :background="background" :foreground="foreground" :pdground="pdground" :icon="icon" :iconSize="iconsize" :lv="lv" :onval="onval" :loadMake="loadMake" :usingComponents="true" @result="qrR" />
				</view>
			</view>
		</view>
		<view class="succBtn">
			<fui-button text="完成" background="#35743D" width='96%' height='72rpx' :margin="['0', '17rpx']"
				radius='50rpx' @click="pricePopup" size="28"></fui-button>
		</view>
	</view>
</template>

<script>
	import {
		baseOssUrl,
		baseOssUrl2
	} from '@/common/settings';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import tkiQrcode from '@/components/tki-qrcode/tki-qrcode.vue'
	export default {
		components: {
			tkiQrcode
		},
		data() {
			return {
				ifShow: false,
				id:'',
				baseOssUrl: baseOssUrl,
				baseOssUrl2:baseOssUrl2,
				form:{},
				val: '', // 要生成的二维码值
				size: 200, // 二维码大小
				unit: 'upx', // 单位
				background: '#ffffff', // 背景色
				foreground: '#000000', // 前景色
				pdground: '#000000', // 角标色
				icon: '', // 二维码图标
				iconsize: 40, // 二维码图标大小
				lv: 3, // 二维码容错级别 ， 一般不用设置，默认就行
				onval: false, // val值变化时自动重新生成二维码
				loadMake: true, // 组件加载完成后自动生成二维码
				src: '' // 二维码生成后的图片地址或base64
			}
		},
		onLoad(params) {
			this.id = params.id
			this.ifFk()
		},
		methods: {

			leftClick() {
				uni.navigateBack({
					delta: 1
				});
			},
			pricePopup() {
				uni.reLaunch({
					url: `/pages/home/home?`
				})
			},
			lookOrder() {
				uni.navigateTo({
					url: `/pages/foodOrderDetails/index?id=${this.form.id}`
				})
			},
			ifFk() {
				this.$http.get(this.$httpApi.ifFk, {
					data: {
						id: this.id
					}
				}).then(res => {
					if(res.f == 1) {
						
						this.details()
					}
				})
			},
			// 生成二维码
			creatQrcode() {
				this.$refs.qrcode._makeCode()
			},
			qrR(res) {
				const imgData = uni.getFileSystemManager().readFileSync(res, 'base64');
				const base64 = 'data:image/png;base64,' + imgData;
				console.log(base64)
				this.src = base64
				this.orderUpdate()
			},
			// 修改订单
			orderUpdate() {
				this.$http.post(this.$httpApi.orderUpdate, {
					data: {
						id:this.id,
						ewm: this.src
					}
				}).then(res => {
					console.log(res)
				})
			},
			// 订单详情
			details() {
				this.$http.get(this.$httpApi.selectCyOrderDetailed, {
					data: {
						id: this.id
					}
				}).then(res => {
					if(res.code == 0) {
						this.form = res.order
						this.val = 'num=' + res.order.number
						this.ifShow = true
						this.creatQrcode()
					}
					console.log(res)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.payCont {
		height: 100vh;
		background: #EFEFEF;
		padding-top: 24rpx;

		.contA {
			background: #FFFFFF;
			border-radius: 16rpx;
			padding: 24rpx;
			position: relative;

			.cont-paycont {
				color: #35743D;
				display: flex;
				flex-direction: column;
				align-items: center;

				.cont-buy {
					font-size: 40rpx;
					font-weight: 500;
					margin-bottom: 24rpx;
				}

				.succes-text {}
			}

			.buy-name {
				font-size: 30rpx;
				font-weight: bold;
				margin: 63rpx 0;

				.b-title {
					margin-bottom: 16rpx;
				}

			}

			.buy-code {
				display: flex;
				justify-content: center;
				border-top: 1px dashed #BFD3C2;
				margin-bottom: 95rpx;

				.img-border {
					margin-top: 18rpx;
					width: 264rpx;
					height: 264rpx;
					border: 1rpx dashed #BFD3C2;
					display: flex;
					justify-content: center;
					align-items: center;

					image {
						width: 240rpx;
						height: 240rpx;

					}
				}

				.yuan1 {
					position: absolute;
					top: 43%;
					left: -35rpx;
					background-color: #EFEFEF;
					border-radius: 50%;
					width: 70rpx;
					height: 70rpx;
				}

				.yuan2 {
					position: absolute;
					top: 43%;
					right: -35rpx;
					background-color: #EFEFEF;
					border-radius: 50%;
					width: 70rpx;
					height: 70rpx;
				}

			}

		}

		.succBtn {
			margin-top: 80rpx;
		}



	}
</style>
